package com.wavehi.web;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author WaveHi
 * @Date 16/9/2021 下午 9:36
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Deal process of login
 */
@WebServlet(urlPatterns="/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户名和密码
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //检验用户名和密码
        boolean isCorrect = username != null && password != null && "admin".equals(username)
                && "root".equalsIgnoreCase(password);
        //响应
        if(isCorrect) {
            //获取请求转发对象
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/page/other/login_success.jsp");
            //转发
            requestDispatcher.forward(req, resp);
        }else {
            //获取请求转发对象
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/page/other/login_fail.jsp");
            //转发
            requestDispatcher.forward(req, resp);
        }
    }
}
